<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>运营商信息</span>
      <el-button style="float: right; padding: 3px 0" type="text" @click="addAd">添加</el-button>
        <el-row>
          <el-col :span="24"><div class="grid-content bg-purple-dark">
            <el-table
              :data="user"
              style="width: 100%">
              <el-table-column
                prop="username"
                label="账号"
                width="180">
              </el-table-column>
              <el-table-column
                prop="password"
                label="密码"
                width="180">
              </el-table-column>
              <el-table-column
                prop="email"
                label="邮箱">
              </el-table-column>
              <el-table-column
                prop="created"
                label="创建时间">
              </el-table-column>
              <el-table-column
                prop="name"
                label="名字">
              </el-table-column>

              <el-table-column
                fixed="right"
                label="状态"
                width="100">
                <template slot-scope="scope">
                  <button type="primary" v-if="scope.row.status==0" @click="updateStatus(scope.row)">禁用</button>
                  <button type="danger" v-else @click="updateStatu(scope.row)">启用</button>
                </template>
              </el-table-column>

              <el-table-column
                fixed="right"
                label="操作"
                width="100">
                <template slot-scope="scope">
                  <el-button @click="updat(scope.row.id)" type="text" size="small">修改</el-button>
                  <el-button @click="del(scope.row.id)" type="text" size="small">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div></el-col>
        </el-row>
    </div>
  </el-card>

</template>

<script>
    export default {
        name: "AdminList",
      data(){
          return{
            table: false,
            dialog: false,
            loading: false,
            user:[],
          }
      },methods:{
        updateStatus:function(){
          this.axios.put("http://localhost:8001/admin/updateStatus",this.user).then(res=>{
            if(res.data.flag){
              alert("成功")
            }else{
              alert("失败")
            }
          })
        },
        updateStatu:function(){
          this.axios.put("http://localhost:8001/admin/updateStatu",this.user).then(res=>{
            if(res.data.flag){
              alert("成功")
            }else{
              alert("失败")
            }
          })
        },
        updat(id){
          this.$router.push("UpdateAdmin?="+id);
        },

          del:function(id){
            this.axios.delete("http://localhost:8001/admin/del/"+id).then(res=>{
              if(res.data.flag){
                location.reload();
                alert("删除成功");
              }
            })
          },
        addAd:function(){
          this.$router.push("AddAdmin")
        },
        findAll:function(){
          this.axios.get("http://localhost:8001/admin/list").then(res=>{
            this.user=res.data.data;
          })
        }
      },mounted(){
        this.findAll();

      }
    }
</script>

<style scoped>

</style>
